/* See LICENSE file for copyright and license details. */
#include <X11/XF86keysym.h>

#define SESSION_FILE "/tmp/dwm-session"

/* appearance */
static const unsigned int borderpx  = 5;        /* border pixel of windows */
static const unsigned int gappx     = 6;        /* gaps between windows */
static const unsigned int snap      = 32;       /* snap pixel */
static const int scalepreview       = 4;        /* tag preview scaling */
static const unsigned int systraypinning = 0;   /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
static const unsigned int systrayonleft = 0;   	/* 0: systray in the right corner, >0: systray on left of status text */
static const unsigned int systrayspacing = 2;   /* systray spacing */
static const int systraypinningfailfirst = 1;   /* 1: if pinning fails, display systray on the first monitor, False: display systray on the last monitor*/
static const int showsystray        = 1;     /* 0 means no systray */
static const int showbar            = 1;     /* 0 means no bar */
static const int topbar             = 1;     /* 0 means bottom bar */
static const Bool viewontag         = True;     /* Switch view on tag switch */
static const double activeopacity   = 1.0f;     /* Window opacity when it's focused (0 <= opacity <= 1) */
static const double inactiveopacity = 0.875f;   /* Window opacity when it's inactive (0 <= opacity <= 1) */
// static       Bool bUseOpacity       = True;     /* Starts with opacity on any unfocused windows */
static const char *fonts[]          = { "Sauce Code Pro Nerd Font:size=13" };
// static const char dmenufont[]       = "monospace:size=10";
static const char col1[]       = "#647b89";
static const char col2[]       = "#444444";
static const char col3[]       = "#38373d";
static const char col4[]       = "#eeeeee";
static const char col5[]        = "#96b3b5";
static const char *colors[][4]      = {
	/*               fg         bg         border     float */
	[SchemeNorm] = { col4, col1, col2, col2 },
	[SchemeSel] =  { col3, col5,  "#ff0000", col5 },
};
static const XPoint stickyicon[]    = { {0,0}, {4,0}, {4,8}, {2,6}, {0,8}, {0,0} }; /* represents the icon as an array of vertices */
static const XPoint stickyiconbb    = {4,8};	/* defines the bottom right corner of the polygon's bounding box (speeds up scaling) */

/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };

static const Rule rules[] = {
	/* xprop(1):
	 *	WM_CLASS(STRING) = instance, class
	 *	WM_NAME(STRING) = title
	 */
	/* class      instance    title       tags mask     isfloating   monitor    float x,y,w,h         floatborderpx*/
	{ "Gimp",     NULL,       NULL,       0,            1,           -1,        50,50,500,500,        5 },
	{ "Firefox",  NULL,       NULL,       1 << 8,       0,           -1,        50,50,500,500,        5 },
};

/* layout(s) */
static const float mfact     = 0.6; /* factor of master area size [0.05..0.95] */
static const int nmaster     = 1;    /* number of clients in master area */
static const int resizehints = 0;    /* 1 means respect size hints in tiled resizals */
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */

static const Layout layouts[] = {
	/* symbol     arrange function */
	{ "Tile",      tile },    /* first entry is default */
	{ "Float",      NULL },    /* no layout function means floating behavior */
	{ "Monocle[M]",      monocle },
};

/* key definitions */
#define MODKEY Mod4Mask
#define TAGKEYS(KEY,TAG) \
	{1, {{MODKEY, KEY}},								view,           {.ui = 1 << TAG} },	\
	{1, {{MODKEY|ControlMask, KEY}},					toggleview,     {.ui = 1 << TAG} }, \
	{1, {{MODKEY|ShiftMask, KEY}},						tag,            {.ui = 1 << TAG} }, \
	{1, {{MODKEY|ControlMask|ShiftMask, KEY}},			toggletag,      {.ui = 1 << TAG} },

/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }

/* commands */
// static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
// static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
static const char *termcmd[]  = { "kitty", NULL };
static const char *rofi_drun[]  = { "rofi", "-show", "drun", NULL };
static const char *rofi_run[]  = { "rofi", "-show", "run", NULL };
static const char *browser[]  = { "brave", NULL };
static const char *emacs[]  = { "emacsclient", "-c", "-a", "'emacs'", NULL };
static const char *brightness_up[]={"brightnessctl", "set", "5%+", NULL};
static const char *brightness_down[]={"brightnessctl", "set", "5%-", NULL};
static const char *volume_mute[]={"pamixer", "-t", NULL};
static const char *volume_up[]={"pamixer", "-i", "5", NULL};
static const char *volume_down[]={"pamixer", "-d", "5", NULL};
static const char *screenshotcmd_sel[] = { "flameshot", "gui", NULL };
static const char *screenshotcmd_full[] = { "flameshot", "full", NULL };
static const char *lockscreencmd[] = { "betterlockscreen", "-l", NULL };

static Keychord keychords[] = {
	/* keys       																 function        argument */

	// backlight adjust
	{1, {{0,XF86XK_MonBrightnessUp}},               spawn,          {.v = brightness_up} },
	{1, {{0,XF86XK_MonBrightnessDown}},             spawn,          {.v = brightness_down} },

	// volume adjust 
	{1, {{0,XF86XK_AudioMute}},                     spawn,          {.v = volume_mute} },
	{1, {{0,XF86XK_AudioRaiseVolume}},              spawn,          {.v = volume_up} },
	{1, {{0,XF86XK_AudioLowerVolume}},              spawn,          {.v = volume_down} },

	// favorite apps
	{2, {{MODKEY,XK_e},{MODKEY,XK_e}},              spawn,          {.v = emacs} },
	{1, {{MODKEY,XK_Return}}, 	 									  spawn,          {.v = termcmd } },
	{2, {{MODKEY,XK_a},{MODKEY,XK_b}}, 			     		spawn,          {.v = browser } },
	{1, {{MODKEY,XK_p}}, 	         									spawn,          {.v = rofi_drun } },
	{1, {{MODKEY|ShiftMask,XK_p}}, 								  spawn,          {.v = rofi_run } },
	{1, {{0,XK_Print}},                             spawn,          {.v = screenshotcmd_sel } },
	{1, {{ShiftMask,XK_Print}},                     spawn,          {.v = screenshotcmd_full } },
	{1, {{MODKEY,XK_x}},                         spawn,          {.v = lockscreencmd } },

	// focus change
	{1, {{MODKEY,XK_j}},          								  focusstack,     {.i = +1 } },
	{1, {{MODKEY,XK_k}},          								  focusstack,     {.i = -1 } },

	// master window number
	{1, {{MODKEY,XK_i}},          								  incnmaster,     {.i = +1 } },
	{1, {{MODKEY,XK_d}},                            incnmaster,     {.i = -1 } },
	{1, {{MODKEY|ShiftMask,XK_Return}},             zoom,           {0} },

	// resize windows
	{1, {{MODKEY,XK_minus}},                        setmfact,       {.f = -0.05} },
	{1, {{MODKEY,XK_equal}},                        setmfact,       {.f = +0.05} },
	{1, {{MODKEY|ShiftMask,XK_equal}},              setcfact,       {.f = +0.25} },
	{1, {{MODKEY|ShiftMask,XK_minus}},              setcfact,       {.f = -0.25} },

	// float control
	{2, {{MODKEY,XK_f},{MODKEY,XK_j}},             moveresize,     {.v = "0x 25y 0w 0h" } },
	{2, {{MODKEY,XK_f},{MODKEY,XK_k}},             moveresize,     {.v = "0x -25y 0w 0h" } },
	{2, {{MODKEY,XK_f},{MODKEY,XK_l}},             moveresize,     {.v = "25x 0y 0w 0h" } },
	{2, {{MODKEY,XK_f},{MODKEY,XK_h}},             moveresize,     {.v = "-25x 0y 0w 0h" } },
	{2, {{MODKEY,XK_r},{MODKEY,XK_j}},             moveresize,     {.v = "0x 0y 0w 25h" } },
	{2, {{MODKEY,XK_r},{MODKEY,XK_k}},             moveresize,     {.v = "0x 0y 0w -25h" } },
	{2, {{MODKEY,XK_r},{MODKEY,XK_l}},             moveresize,     {.v = "0x 0y 25w 0h" } },
	{2, {{MODKEY,XK_r},{MODKEY,XK_h}},             moveresize,     {.v = "0x 0y -25w 0h" } },
	{2, {{MODKEY,XK_e},{MODKEY,XK_k}},             moveresizeedge, {.v = "t"} },
	{2, {{MODKEY,XK_e},{MODKEY,XK_j}},             moveresizeedge, {.v = "b"} },
	{2, {{MODKEY,XK_e},{MODKEY,XK_h}},             moveresizeedge, {.v = "l"} },
	{2, {{MODKEY,XK_e},{MODKEY,XK_l}},             moveresizeedge, {.v = "r"} },
	{3, {{MODKEY,XK_e},{MODKEY,XK_r},{MODKEY,XK_k}},     moveresizeedge, {.v = "T"} },
	{3, {{MODKEY,XK_e},{MODKEY,XK_r},{MODKEY,XK_j}},     moveresizeedge, {.v = "B"} },
	{3, {{MODKEY,XK_e},{MODKEY,XK_r},{MODKEY,XK_h}},     moveresizeedge, {.v = "L"} },
	{3, {{MODKEY,XK_e},{MODKEY,XK_r},{MODKEY,XK_l}},     moveresizeedge, {.v = "R"} },

	// layout change
	{1, {{MODKEY,XK_space}},                        togglefloating, {0} },
	{1, {{MODKEY,XK_s}},                            togglesticky,   {0} },
	{1, {{MODKEY,XK_f}},                            togglefullscr,  {0} },
	{1, {{MODKEY|ShiftMask,XK_Tab}},                layoutscroll,   {.i = -1 } },
	{1, {{MODKEY,XK_Tab}},                          layoutscroll,   {.i = +1 } },

	{1, {{MODKEY,XK_0}},                            view,           {.ui = ~0 } },
	{1, {{MODKEY|ShiftMask,XK_0}},                  tag,            {.ui = ~0 } },

	// tag manage
	{1, {{MODKEY,XK_period}},                       viewnext,       {0} },
	{1, {{MODKEY,XK_comma}},                        viewprev,       {0} },
	{1, {{MODKEY|ShiftMask,XK_period}},             tagtonext,      {0} },
	{1, {{MODKEY|ShiftMask,XK_comma}},              tagtoprev,      {0} },
	TAGKEYS(                        XK_1,                      0)
	TAGKEYS(                        XK_2,                      1)
	TAGKEYS(                        XK_3,                      2)
	TAGKEYS(                        XK_4,                      3)
	TAGKEYS(                        XK_5,                      4)
	TAGKEYS(                        XK_6,                      5)
	TAGKEYS(                        XK_7,                      6)
	TAGKEYS(                        XK_8,                      7)
	TAGKEYS(                        XK_9,                      8)

	// dwm basic
	{1, {{MODKEY|ShiftMask,XK_q}},                   quit,           {0} },
	{1, {{MODKEY|ShiftMask,XK_r}},                   quit,           {1} }, 
	{1, {{MODKEY,XK_q}},                            killclient,     {0} },
};

/* button definitions */
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */
static Button buttons[] = {
	/* click                event mask      button          function        argument */
	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
	{ ClkWinTitle,          0,              Button2,        zoom,           {0} },
	{ ClkStatusText,        0,              Button2,        spawn,          {.v = termcmd } },
	{ ClkClientWin,         MODKEY,         Button1,        movemouse,      {0} },
	{ ClkClientWin,         MODKEY,         Button2,        togglefloating, {0} },
	{ ClkClientWin,         MODKEY,         Button3,        resizemouse,    {0} },
	{ ClkTagBar,            0,              Button1,        view,           {0} },
	{ ClkTagBar,            0,              Button3,        toggleview,     {0} },
	{ ClkTagBar,            MODKEY,         Button1,        tag,            {0} },
	{ ClkTagBar,            MODKEY,         Button3,        toggletag,      {0} },
};

